package com.huarui.companypackage.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.ewaf.framework.dao.impl.BaseDaoImpl;
import org.springframework.orm.ibatis.SqlMapClientCallback;

import com.huarui.companypackage.dao.IPackageCompanyTypeDao;
import com.huarui.companypackage.model.PackageCompanyType;
import com.ibatis.sqlmap.client.SqlMapExecutor;

public class PackageCompanyTypeDaoImpl extends BaseDaoImpl implements IPackageCompanyTypeDao {

	@Override
	public void batchInsertPackageCompanyType(final List<PackageCompanyType> packageCompanyTypes) {
		getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
			
			@Override
			public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
				executor.startBatch();
				int batch = 0;
				for (PackageCompanyType packageCompanyType : packageCompanyTypes) {
					executor.insert(namespace + ".create", packageCompanyType);
					batch++;
					if (batch == 50) {
						executor.executeBatch();
						batch = 0;
					}
				}
				executor.executeBatch();
				return null;
			}
		});
	}

}
